#include "middle.h"
#include "ui_middle.h"
#include <QListWidget>
#include <QPushButton>
#include <QDebug>

Middle::Middle(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Middle)
{
    ui->setupUi(this);

    ui->stackedWidget->setCurrentIndex(0);

    setListT1();

    setListT2();

    setListT3();

    setPictureWall();

    setpicture_2();

    setGallery();

    setSongList();

    setSongList2();

    setButtonIcon();
    setSecondweight();

    setlabels1();
       setlabels2();
   //    setlayouts3();
       setlabely1();
       setlabely2();
       setlabely3();
       setlabely4();
       setwidgetSinger0();
       setwidgetSinger1();
       setwidgetSinger2();
       setwidgetSinger3();
//       setwidgetSinger4();
       setwidMus1();
       setwidMus2();
       setwidMus3();
       setwidMus4();

       connect(ui->return_2,&QPushButton::clicked,[=](){
           on_return_2_clicked();
       });

//       on_return_2_clicked();

}

Middle::~Middle()
{
    delete ui;
}

void Middle::setSecondweight()
{
    ui->label1->setGeometry(0,0,1000,70);
    //ui->label2->setPixmap(QPixmap(":/image/Dis35.png"));
    ui->label1->setStyleSheet("background-color: #00FF00;");//绿色背景
    ui->label2->setGeometry(0,-5,150,70);//前两个参数表示label左上角位置后面分别是宽和高
    //img->scaled(width,height,Qt::KeepAspectRatio);
    ui->label2->setPixmap(QPixmap(":/aaa/QQyinle-.png"));//QQ音乐
                                   //:/image/QQyinle-.png
    ui->label3->setGeometry(200,15,20,35);//左移
    ui->label3->setPixmap(QPixmap(":/aaa/后退.png"));
    ui->label4->setGeometry(230,15,20,35);//右移
    ui->label4->setPixmap(QPixmap(":/aaa/前进.png"));

    ui->labels->setGeometry(400,15,20,35);//小喇叭
    ui->labels->setPixmap(QPixmap(":/aaa/horn.png"));
    //搜索框



    ui->label5->setGeometry(440,15,50,35);//头像
    ui->label5->setPixmap(QPixmap(":/aaa/Acg4.png"));
//      ui->label6->setGeometry(490,-5,80,60);//账号
//       ui->label6->setText("sys的账号");

     ui->label7->setGeometry(600,15,60,35);//VIP
     ui->label7->setPixmap(QPixmap(":/aaa/vip.png"));
      ui->label8->setGeometry(660,15,40,35);//皮肤
     ui->label8->setPixmap(QPixmap(":/aaa/btn_skin_n.png"));
     ui->label9->setGeometry(700,15,20,35);//爱心
    ui->label9->setPixmap(QPixmap(":/aaa/btn_unlike_h.png"));
    ui->label10->setGeometry(730,15,20,35);//邮件
   ui->label10->setPixmap(QPixmap(":/aaa/邮件.png"));
   ui->label11->setGeometry(770,15,30,35);//右移
   ui->label11->setPixmap(QPixmap(":/aaa/listall.png"));//列表
   ui->label12->setGeometry(810,15,60,35);//右移
   ui->label12->setText("听我想听");
   ui->pushButtons1->setStyleSheet("background-color: rgb(255, 255, 255)");
   ///////////////////////////////////
   //下面
   ui->pic1_3->setPixmap(QPixmap(":/aaa/21.png"));
   ui->pic2_3->setText("有何不可");
   ui->pic3_3->setPixmap(QPixmap(":/aaa/btn_unlike_h.png"));
   ui->pushButtons1->setIcon(QIcon(":/aaa/心动.png"));
   ui->pushButtons1->setStyleSheet("background-color: rgb(255, 255, 255)");
   ui->pushButtons2->setIcon(QIcon(":/aaa/上一曲2.png"));
   ui->pushButtons2->setStyleSheet("background-color: rgb(255, 255, 255)");




   ui->pushButtons3->setStyleSheet("background-color: rgb(255, 255, 255)");
   ui->pushButtons4->setIcon(QIcon(":/aaa/下一曲2.png"));
   ui->pushButtons4->setStyleSheet("background-color: rgb(255, 255, 255)");
   ui->pushButtons5->setIcon(QIcon(":/aaa/词.png"));
   ui->pushButtons5->setStyleSheet("background-color: rgb(255, 255, 255)");
   ui->labely1_4->setPixmap(QPixmap(":/aaa/标准.png"));
   ui->labely2_4->setPixmap(QPixmap(":/aaa/voice.png"));
   ui->labely3_4->setPixmap(QPixmap(":/aaa/voice2.png"));
   ui->labely4_4->setPixmap(QPixmap(":/aaa/all.png"));
   ui->labely5_3->setPixmap(QPixmap(":/aaa/最近播放.png"));

   QPalette palette;
   //设置主窗口背景颜色
   palette.setColor(QPalette::Window,QColor(255, 255, 255));
   this->setPalette(palette);
   //时间
   ui->labelz1->setText("0:00");
   ui->labelz2->setText("3:21");
}

void Middle::setButtonIcon()
{
    ui->pushButton_2->setIcon(QIcon(":/image/os-icon-add.png"));
    ui->pushButton_5->setIcon(QIcon(":/image/os-icon-add.png"));
    ui->btnPerL->setIcon(QIcon(":/image/show_more.png"));
    ui->btnPerR->setIcon(QIcon(":/image/show_less.png"));
    ui->btnPerL_2->setIcon(QIcon(":/image/xiangzuo.png"));
    ui->btnPerR_2->setIcon(QIcon(":/image/xiangyou.png"));
    ui->TB_tab2_1->setIcon(QIcon(":/image/recommend/图书.png"));
    ui->TB_tab2_2->setIcon(QIcon(":/image/recommend/幼儿.png"));
    ui->TB_tab2_3->setIcon(QIcon(":/image/recommend/音乐.png"));
    ui->TB_tab2_4->setIcon(QIcon(":/image/recommend/开心.png"));
    ui->TB_tab2_5->setIcon(QIcon(":/image/recommend/情感.png"));
    ui->widgetPer1_1->setStyleSheet("border-image:url(:/image/recommend/36.png)");
    ui->widgetPer1_2->setStyleSheet("border-image:url(:/image/recommend/37.png)");
    ui->widgetPer1_3->setStyleSheet("border-image:url(:/image/recommend/38.png)");
    ui->widgetPer1_4->setStyleSheet("border-image:url(:/image/recommend/39.png)");
    ui->widgetPer1_5->setStyleSheet("border-image:url(:/image/recommend/40.png)");
    ui->widgetPer1_6->setStyleSheet("border-image:url(:/image/recommend/41.png)");
    ui->widgetPer1_7->setStyleSheet("border-image:url(:/image/recommend/42.png)");
    ui->widgetPer1_8->setStyleSheet("border-image:url(:/image/recommend/43.png)");
    ui->toolButton_5->setIcon(QIcon(":/image/xiangzuo.png"));
    ui->toolButton_6->setIcon(QIcon(":/image/xiangyou.png"));
    ui->widget_8->setStyleSheet("border-image:url(:/image/recommend/44.png)");
    ui->widget_9->setStyleSheet("border-image:url(:/image/recommend/45.png)");
    ui->widget_12->setStyleSheet("border-image:url(:/image/recommend/46.png)");
    ui->widget_13->setStyleSheet("border-image:url(:/image/recommend/47.png)");
    ui->widget_23->setStyleSheet("border-image:url(:/image/recommend/48.png)");
    ui->widget_24->setStyleSheet("border-image:url(:/image/recommend/49.png)");
    ui->label_27->setPixmap(QPixmap(":/image/imagesys/songlist-01.png"));
    ui->label_26->setPixmap(QPixmap(":/image/imagesys/songlist-01.png"));
    ui->label_6->setPixmap(QPixmap(":/image/imagesys/yaogun0.png"));
}

void Middle::on_return_2_clicked()
{
    MainWindow *fater=new MainWindow();
    this->close();
    fater->show();
}

void Middle::setListT1()
{

    ui->btn_recommended->setText("推荐");
    ui->btn_recommended->setIcon(QIcon(":/image/btn_label/2.png"));
    connect(ui->btn_recommended,&QToolButton::clicked,[=](){
        ui->stackedWidget->setCurrentIndex(0);
    });


    ui->btn_musicHall->setText("音乐馆");
    ui->btn_musicHall->setIcon(QIcon(":/image/btn_label/3.png"));
    ui->tabWidget->setCurrentIndex(0);
    connect(ui->btn_musicHall,&QToolButton::clicked,[=](){
        ui->stackedWidget->setCurrentIndex(1);
    });

    ui->btn_video->setText("视频");
    ui->btn_video->setIcon(QIcon(":/image/btn_label/1.png"));
    ui->btn_radar->setText("雷达");
    ui->btn_radar->setIcon(QIcon(":/image/btn_label/fm.png"));
}

void Middle::setListT2()
{

    ui->btn_myFavorite->setText("我喜欢");
    ui->btn_myFavorite->setIcon(QIcon(":/image/btn_label/like.png"));
    ui->tabWidget_p3->setCurrentIndex(0);
    connect(ui->btn_myFavorite,&QToolButton::clicked,[=](){
        ui->stackedWidget->setCurrentIndex(2);
    });


    ui->btn_ll->setText("本地和下载");
    ui->btn_ll->setIcon(QIcon(":/image/os-icon-download.png"));
    ui->tabWidget_p4->setCurrentIndex(0);
    connect(ui->btn_ll,&QToolButton::clicked,[=](){
        ui->stackedWidget->setCurrentIndex(3);
    });

    ui->btn_recent->setText("最近播放");
    ui->btn_recent->setIcon(QIcon(":/image/btn_label/4.png"));
    ui->btn_lt->setText("试听列表");
    ui->btn_lt->setIcon(QIcon(":/image/songlist-01.png"));
}

void Middle::setListT3() //设置我喜欢的音乐
{
    ui->list_3->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->list_3->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    QListWidgetItem *item1 = new QListWidgetItem(ui->list_3);
    item1->setIcon(QIcon(":/image/btn_label/2.png"));
    item1->setText("「戏腔」“百态众生");
    QListWidgetItem *item2 = new QListWidgetItem(ui->list_3);
    item2->setIcon(QIcon(":/image/btn_label/2.png"));
    item2->setText(" 却道戏子无情”");
}

void Middle::setPictureWall() //添加轮播图
{
    pictureWidget = new PictureWidget();
    ui->today_recommend->addWidget(pictureWidget);
}

void Middle::setpicture_2() //添加轮播图
{
    picture_2 = new p2();
    ui->P2_tab1_f->addWidget(picture_2);
}

void Middle::setGallery()
{
    //初始话数据
    gallerPrivate = new GalleryPrivate();

    QList<GalleryItem * > items;
    //添加5个数据
    GalleryItem *item = new GalleryItem();
    item->setPicture(":/image/recommend/11.png");
    items.append(item);
    //2
    GalleryItem *item2 = new GalleryItem();
    item2->setPicture(":/image/recommend/12.png");
    items.append(item2);

    GalleryItem *item3 = new GalleryItem();
    item3->setPicture(":/image/recommend/13.png");
    items.append(item3);

    GalleryItem *item4 = new GalleryItem();
    item4->setPicture(":/image/recommend/14.png");
    items.append(item4);

    GalleryItem *item5 = new GalleryItem();
    item4->setPicture(":/image/recommend/20.png");
    items.append(item5);

    gallerPrivate->setItemRes(item->width(),item->height(),items);

    ui->everyone_listen->setContentsMargins(0,0,0,0);
    ui->everyone_listen->addWidget(gallerPrivate->getItemViewport());

    this->setStyleSheet("QWidget#customization{border:1px; background:white; border-radius:5px;}");
}

void Middle::setSongList()
{
    songList = new SongList();

    QList<SongList_p *> s_items;

    SongList_p * item = new SongList_p();
    item->setPicture(":/image/recommend/15.png");
    item->setMessage("耳机杀手.那些洗刷你灵魂的BGM");
    s_items.append(item);

    SongList_p * item2 = new SongList_p();
    item2->setPicture(":/image/recommend/16.png");
    item2->setMessage("瑞，你在听吗？");
    s_items.append(item2);

    SongList_p * item4 = new SongList_p();
    item4->setPicture(":/image/recommend/18.png");
    item4->setMessage("戏腔.本是戏中人，何来入戏深");
    s_items.append(item4);

    SongList_p * item5 = new SongList_p();
    item5->setPicture(":/image/recommend/19.png");
    item5->setMessage("曲尽人散");
    s_items.append(item5);

    songList->setItemRes(item->width(),item->height(),s_items);

    ui->verticalLayout_8->setContentsMargins(0,0,0,0);
    ui->verticalLayout_8->addWidget(songList->getItemViewport());

    this->setStyleSheet("QWidget#customization{border:1px; background:white; border-radius:5px;}");

}

void Middle::setSongList2()
{
    songList2 = new SongList();

    QList<SongList_p *> s_items;

//    ui->widMus1_2->setStyleSheet("border-image:url(:/image/recommend/50.png)");
//    ui->widMus2_2->setStyleSheet("border-image:url(:/image/recommend/51.png)");
//    ui->widMus3_2->setStyleSheet("border-image:url(:/image/recommend/52.png)");
//    ui->widMus4_2->setStyleSheet("border-image:url(:/image/recommend/53.png)");

    SongList_p * item = new SongList_p();
    item->setPicture(":/image/recommend/50.png");
    item->setMessage("落花漫天，又闻诗意");
    s_items.append(item);

    SongList_p * item2 = new SongList_p();
    item2->setPicture(":/image/recommend/51.png");
    item2->setMessage("谁的青春无回忆·国漫");
    s_items.append(item2);

    SongList_p * item4 = new SongList_p();
    item4->setPicture(":/image/recommend/52.png");
    item4->setMessage("国风戏腔");
    s_items.append(item4);

    SongList_p * item5 = new SongList_p();
    item5->setPicture(":/image/recommend/53.png");
    item5->setMessage("ACG");
    s_items.append(item5);

    songList2->setItemRes(item->width(),item->height(),s_items);

    ui->verticalLayout_16->setContentsMargins(0,0,0,0);
    ui->verticalLayout_16->addWidget(songList2->getItemViewport());

    this->setStyleSheet("QWidget#customization{border:1px; background:white; border-radius:5px;}");

}

void Middle::on_btnPerL_clicked()
{
    int num = gallerPrivate->getPreviousItemIndex();
    gallerPrivate->showImage(num);
}

void Middle::on_btnPerR_clicked()
{
    int num =gallerPrivate->getNextItemIndex();
    gallerPrivate->showImage(num);
}

void Middle::setlabels1()  //我喜欢的大图
{
    ui->labels1->setPixmap(QPixmap(":/image/imagesys/zongyi0.png"));
    ui->labels1->setGeometry(211,192,685,120);

}
void Middle::setlabels2()  //文字介绍
{
    ui->labels2->setText("华语    流行      摇滚     民谣     电子    轻音乐    综艺     ACC     XBOX");
    ui->labels2->setGeometry(280,330,600,40);

}

void Middle::setlabely1()  //我喜欢的小图
{
    ui->labely1->setPixmap(QPixmap(":/image/imagesys/yaogun1.png"));
//    ui->labels1->setGeometry(211,192,685,120);
}
void Middle::setlabely2()  //我喜欢的大图
{
    ui->labely2->setPixmap(QPixmap(":/image/imagesys/yaogun2.png"));
//    ui->labels1->setGeometry(211,192,685,120);
}
void Middle::setlabely3()  //我喜欢的大图
{
    ui->labely3->setPixmap(QPixmap(":/image/imagesys/yaogun2.png"));
//    ui->labels1->setGeometry(211,192,685,120);
}
void Middle::setlabely4()  //我喜欢的大图
{
    ui->labely4->setPixmap(QPixmap(":/image/imagesys/yaogun2.png"));
//    ui->labels1->setGeometry(211,192,685,120);
}
void Middle::setwidgetSinger0()
{
    // 部分核心代码片段 在Qt 5.7中编译通过
//    QWidget * widget = new QWidget;
    ui->widgetSinger0->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/singer0.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widgetSinger0->setPalette(palette);
    ui->ptnSinger0->setIcon(QIcon(":/image/imagesys/guanzhu.png"));
}
void Middle::setwidgetSinger1()
{
    // 部分核心代码片段 在Qt 5.7中编译通过
//    QWidget * widget = new QWidget;
    ui->widgetSinger1->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/singer1.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widgetSinger1->setPalette(palette);
    ui->ptnSinger1->setIcon(QIcon(":/image/imagesys/guanzhu.png"));
}
void Middle::setwidgetSinger2()
{
    // 部分核心代码片段 在Qt 5.7中编译通过
//    QWidget * widget = new QWidget;
    ui->widgetSinger2->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/singer2.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widgetSinger2->setPalette(palette);
    ui->ptnSinger2->setIcon(QIcon(":/image/imagesys/guanzhu.png"));
}
void Middle::setwidgetSinger3()
{
    // 部分核心代码片段 在Qt 5.7中编译通过
//    QWidget * widget = new QWidget;
    ui->widgetSinger3->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/singer3.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widgetSinger3->setPalette(palette);
    ui->ptnSinger3->setIcon(QIcon(":/image/imagesys/guanzhu.png"));
}

void Middle::setwidMus1()
{
    ui->widMus1->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/linglei1.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widMus1->setPalette(palette);
}
void Middle::setwidMus2()
{
    ui->widMus2->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/linglei2.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widMus2->setPalette(palette);
}
void Middle::setwidMus3()
{
    ui->widMus3->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/linglei3.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widMus3->setPalette(palette);
}
void Middle::setwidMus4()
{
    ui->widMus4->setAutoFillBackground(true);
    QImage image;
    QPalette palette;
    image.load(":/image/imagesys/linglei4.png"); // 指定图片所在位置及图片名
    palette.setBrush(this->backgroundRole(),QBrush(image));
    ui->widMus4->setPalette(palette);
}
